package com.bingxue.edu.management.shop.controller;

import com.bingxue.edu.framework.common.model.PageQuery;
import com.bingxue.edu.framework.common.model.Pagination;
import com.bingxue.edu.framework.common.model.Response;
import com.bingxue.edu.framework.security.ApiResource;
import com.bingxue.edu.management.shop.model.entity.SellRecord;
import com.bingxue.edu.management.shop.model.query.SellRecordQuery;
import com.bingxue.edu.management.shop.model.query.SellRecordStatsQuery;
import com.bingxue.edu.management.shop.model.req.SellRecordUpdateReq;
import com.bingxue.edu.management.shop.model.resp.SellRecordResp;
import com.bingxue.edu.management.shop.model.resp.SellRecordStatsResp;
import com.bingxue.edu.management.shop.service.SellRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 销售顾问业绩
 */
@Tag(name = "销售顾问业绩")
@RestController
@RequestMapping("/shop/sell-record")
@RequiredArgsConstructor
public class SellRecordController {

    private final SellRecordService sellRecordService;

    @Operation(summary = "分页查询销售顾问业绩")
    @ApiResource("shop:sell-record:read")
    @GetMapping("/page")
    public Response<Pagination<SellRecordResp>> getSellRecordPage(SellRecordQuery query, PageQuery pageQuery) {
        return Response.success(Pagination.of(sellRecordService.getSellRecordPage(query, pageQuery)));
    }

    @Operation(summary = "查询销售顾问业绩列表")
    @ApiResource("shop:sell-record:read")
    @GetMapping("/list")
    public Response<List<SellRecordResp>> getSellRecordList(SellRecordQuery query) {
        return Response.success(sellRecordService.getSellRecordList(query));
    }

    @Operation(summary = "查询销售顾问业绩统计")
    @ApiResource("shop:sell-record:read")
    @GetMapping("/statsList")
    public Response<List<SellRecordStatsResp>> getSellRecordStats(SellRecordStatsQuery query) {
        return Response.success(sellRecordService.getSellRecordStats(query));
    }

    @Operation(summary = "更新销售顾问业绩")
    @ApiResource("shop:sell-record:write")
    @PostMapping("/update/{sellRecordId}")
    public Response<Void> updateSellRecord(SellRecordUpdateReq req, @PathVariable String sellRecordId) {
        SellRecord sellRecord = sellRecordService.copyById(req,sellRecordId);
        sellRecordService.updateById(sellRecord);
        return Response.success();
    }

}
